

*-------------------------------------------------------------------------*
* This file produces Figures 1 & 2 in the paper.                          *
*																		  *
* Jeffrey K. Staton													      *
* July 6, 2021															  *
* Last updated, April 3, 2024											  *
*-------------------------------------------------------------------------*

clear
*cd " " // Set working directory
cd "/Users/jkstato/Dropbox/Research/Current Projects/Comp Law/1 - CompLaw JLC Replication/Replication Figures"

***************************************************************************
/*FIGURE 1 
***************************************************************************
Figure 1 requires four plots, one each for economic development, democracy 
de jure independence and de facto independence. We create each in turn. This
requires a little data merging.*/ 

// De jure independence 
	clear
	insheet using "Feld_Voigt.csv", comma  
		
	
	drop dejure_index_old- defacto_index_old  //Keep only the new Feld & Voigt measure		
	label variable cname 	"Country"
	label variable ccode "Country COW abbreviation"
	label variable dejure_index "Feld and Voigt de jure index"
	rename cname country_name
	
//Create dummy for whether country was in the complaw sample 
	gen sample_complaw=.
	replace sample_complaw = 1 if country_name =="Albania"
	replace sample_complaw = 1 if country_name =="Algeria"
	replace sample_complaw = 1 if country_name =="Australia"
	replace sample_complaw = 1 if country_name =="Argentina"
	replace sample_complaw = 1 if country_name =="Austria"		
	replace sample_complaw = 1 if country_name =="Belgium"
	replace sample_complaw = 1 if country_name =="Benin"
	replace sample_complaw = 1 if country_name =="Bosnia and Herzogovina"
	replace sample_complaw = 1 if country_name =="Bolivia"
	replace sample_complaw = 1 if country_name =="Burkina Faso"
	replace sample_complaw = 1 if country_name =="Benin"
	replace sample_complaw = 1 if country_name =="Bulgaria"
	replace sample_complaw = 1 if country_name =="Canada"
	replace sample_complaw = 1 if country_name =="Chile"
	replace sample_complaw = 1 if country_name =="Colombia"
	replace sample_complaw = 1 if country_name =="Croatia"
	replace sample_complaw = 1 if country_name =="Dominican Republic"
	replace sample_complaw = 1 if country_name =="Ecuador"
	replace sample_complaw = 1 if country_name =="El Salvador"
	replace sample_complaw = 1 if country_name =="France"
	replace sample_complaw = 1 if country_name =="Germany"
	replace sample_complaw = 1 if country_name =="Guatemala"
	replace sample_complaw = 1 if country_name =="Hungary"
	replace sample_complaw = 1 if country_name =="India"
	replace sample_complaw = 1 if country_name =="Indonesia"
	replace sample_complaw = 1 if country_name =="Ireland"
	replace sample_complaw = 1 if country_name =="Israel"
	replace sample_complaw = 1 if country_name =="Italy"
	replace sample_complaw = 1 if country_name =="Lithuania"
	replace sample_complaw = 1 if country_name =="Luxembourg"
	replace sample_complaw = 1 if country_name =="Madagascar"
	replace sample_complaw = 1 if country_name =="New Zealand"
	replace sample_complaw = 1 if country_name =="Niger"
	replace sample_complaw = 1 if country_name =="Poland"
	*	replace sample_complaw = 1 if country_name =="Romania"
	replace sample_complaw = 1 if country_name =="Russia"
	replace sample_complaw = 1 if country_name =="South Africa"
	replace sample_complaw = 1 if country_name =="Korea_South"
	replace sample_complaw = 1 if country_name =="Spain"
	replace sample_complaw = 1 if country_name =="Turkey"
	replace sample_complaw = 1 if country_name =="United States"
	replace sample_complaw = 1 if country_name =="Venezuela"
	replace  sample_complaw=0 if  sample_complaw==.
	label variable sample_complaw "Is country in the complaw sample (1 is year)?"
		
//Plot for discussion of the sample	
	twoway  kdensity dejure_index if sample_complaw==1, xlabel(0(.2)1.0) ///
		legend(off) lcolor(red) lwidth(medthick) scheme(s1mono) ///
		text(3.5 .73 "CompLaw Sample", color(red) size(medium) place(e)) ///
		ytick(.5)  plotregion(style(none)) ///
		|| 	kdensity dejure_index, lcolor(black) lwidth(medthick) ///
		xtitle(De jure judicial independence (Voigt, Gutmann and Feld 2015)) ///
		ytitle(Density) text(1.5 .34 "All States", color(black) size(medium) place(e)) 
	
		gr export "dejure.pdf", replace  /*This is the PDF of the comparison of the CompLaw and Global
												samples wrt de jure independence.*/
		gr export "dejure.eps", replace
		*sum dejure_index if sample_complaw==1
		*sum dejure_index
// Economic Development, De facto judicial independence and democracy
	clear
	use "V-Dem-v11.1-2003.dta", clear  // This the Varities of Democracy data set, Version 4.2
	keep  country_name country_id country_text_id COWcode year e_migdppcln e_polity2
	rename COWcode cowcode
	
/*Again, create the dummy for whether country was in our analysis */ 
	gen sample_complaw=.
	replace sample_complaw = 1 if country_name =="Albania"
	replace sample_complaw = 1 if country_name =="Algeria"
	replace sample_complaw = 1 if country_name =="Australia"
	replace sample_complaw = 1 if country_name =="Argentina"
	replace sample_complaw = 1 if country_name =="Austria"		
	replace sample_complaw = 1 if country_name =="Belgium"
	replace sample_complaw = 1 if country_name =="Benin"
	replace sample_complaw = 1 if country_name =="Bosnia and Herzogovina"
	replace sample_complaw = 1 if country_name =="Bolivia"
	replace sample_complaw = 1 if country_name =="Burkina Faso"
	replace sample_complaw = 1 if country_name =="Benin"
	replace sample_complaw = 1 if country_name =="Bulgaria"
	replace sample_complaw = 1 if country_name =="Canada"
	replace sample_complaw = 1 if country_name =="Chile"
	replace sample_complaw = 1 if country_name =="Colombia"
	replace sample_complaw = 1 if country_name =="Croatia"
	replace sample_complaw = 1 if country_name =="Dominican Republic"
	replace sample_complaw = 1 if country_name =="Ecuador"
	replace sample_complaw = 1 if country_name =="El Salvador"
	replace sample_complaw = 1 if country_name =="France"
	replace sample_complaw = 1 if country_name =="Germany"
	replace sample_complaw = 1 if country_name =="Guatemala"
	replace sample_complaw = 1 if country_name =="Hungary"
	replace sample_complaw = 1 if country_name =="India"
	replace sample_complaw = 1 if country_name =="Indonesia"
	replace sample_complaw = 1 if country_name =="Ireland"
	replace sample_complaw = 1 if country_name =="Israel"
	replace sample_complaw = 1 if country_name =="Italy"
	replace sample_complaw = 1 if country_name =="Lithuania"
	replace sample_complaw = 1 if country_name =="Luxembourg"
	replace sample_complaw = 1 if country_name =="Madagascar"
	replace sample_complaw = 1 if country_name =="New Zealand"
	replace sample_complaw = 1 if country_name =="Niger"
	replace sample_complaw = 1 if country_name =="Poland"
	* replace sample_complaw = 1 if country_name =="Romania"
	replace sample_complaw = 1 if country_name =="Russia"
	replace sample_complaw = 1 if country_name =="South Africa"
	replace sample_complaw = 1 if country_name =="Korea_South"
	replace sample_complaw = 1 if country_name =="Spain"
	replace sample_complaw = 1 if country_name =="Turkey"
	replace sample_complaw = 1 if country_name =="United States"
	replace sample_complaw = 1 if country_name =="Venezuela"
	replace  sample_complaw=0 if  sample_complaw==.
	label variable sample_complaw "Is country in the complaw sample (1 is year)?"
	
	drop if cowcode==. /*Get rid of observations if we don't know the cow code*/
		
	save "VDem_2003_small", replace  // V-Dem data only for 2003
	clear
		
//Load Latent Judicial Independence data from Linzer and Staton (2015)
	insheet using "LJI-estimates-20170321.csv" , comma clear
	rename ccode cowcode
	keep if year==2003
	tab year
	drop year
	keep lji cowcode country
	sort cowcode 
	save "LJI_small", replace    // LJI data for only 2003
		
	clear
		
	use "VDem_2003_small.dta", clear //Load V-Dem data for 2003
	sort cowcode
	
	merge 1:1 cowcode using "LJI_small"  // Merge with LJI data
	drop if country_name=="".            //Dropping small countries which were not matched with V-Dem data
		

//De facto independence Plot 
	twoway  kdensity lji if sample_complaw==1, lcolor(red) ///
		lwidth(medthick) scheme(s1mono) plotregion(style(none)) ///
		legend(off) xtitle(De facto judicial independence (Linzer and Staton 2015)) ///
		text(1.23 .7  "CompLaw Sample", color(red) size(medium) place(e))  ///
		ytitle(Density) ///
		|| 	kdensity lji, lcolor(black) lwidth(medthick) color(black)	///
		text(1.2 .04  "All States", color(black) size(medium) place(e))
		gr export "defacto.pdf", replace	 /*This is the PDF of the comparison of the CompLaw and Global
													samples wrt de facto judicial independence.*/ 
		gr export "defacto.eps", replace

//ln(GDP/cap) plot
	twoway kdensity e_migdppcln if sample_complaw==1, lcolor(red) ///
		lwidth(medthick) scheme(s1mono) plotregion(style(none))  ///
		legend(off) xlabel(5 (1) 12) ytitle(Density) ///
		xtitle(Economic Development (ln(GDP/cap))) ///
		text(.36 9 "CompLaw Sample", color(red) size(medium) place(e)) ///
		|| 	kdensity  e_migdppcln, lcolor(black) lwidth(medthick) color(black)	///
		text(.22 7 "All States", color(black) size(medium) place(e))
		gr export "lngdp.pdf", replace	/*This is the PDF of the comparison of the 
										CompLaw and Global samples wrt GDP/cap.*/ 
		gr export "lngdp.eps", replace								
	
//Polity IV plot for discussion of the sample	
	twoway  kdensity e_polity2 if sample_complaw==1, lcolor(red) ///
	lwidth(medthick) scheme(s1mono) plotregion(style(none))  bwidth(3) ///
	legend(off) xlabel(-10 (5) 10) ytitle(Density) xtitle(Level of Democracy (Polity IV)) ///
	text(.08 -.3 "CompLaw Sample", color(red) size(medium) place(e)) ///
	|| 	kdensity  e_polity2, bwidth(3) lcolor(black) lwidth(medthick) color(black)	///
	text(.035 -5 "All States", color(black) size(medium) place(e))

	graph export "polity.pdf", replace	/*This is the PDF of the comparison of the CompLaw and Global
													samples wrt the Polity 2 measure.*/ 
	graph export "polity.eps", replace
	
***************************************************************************
*Figure 2:																  *
*There are two panels, one for the policy challenged and one for the 	  *
*complainant.															  *
***************************************************************************
use "alldata_March182024.dta", clear

*Drop courts for which we are not done coding: Portugal (177), Brazil (31), and Bulgarian Supreme Court (257), Romania (181) (not sure if got the right cases)

	drop if countryid==31
	drop if countryid==177
	drop if countryid==181
	drop if countryid==257

*Drop courts without germane cases
		
*DR
	drop if countryid==62 // DR
	drop if countryid==258 // French Council of State	
	drop if countryid==213 //Switzerland
	drop if countryid==257 //Bulgaria SAC

label define action 1 "National Statute" 2 "Sub-national Statute" ///
		3 "National Agency Ruling" 4 "Sub-national Agency Ruling" ///
		5 "National Exec. Order" 6 "Sub-national Exec. Order" 	  ///
		7 "International Treaty" 8 "National Referendum"         ///
		9 "Sub-national Referendum" 10 "National Const. Provision" ///
		11 "Sub-national Const. Provision" 12 "Other" ///
		13 "Pending Legislation"
label values actiontype action

*Panel B
catplot actiontype,  var1opts(sort(1) desc) scheme(s1mono) ytitle(Frequency) l1title("") title(Types of Policies)
gr save "fig2_b", replace
gr export "fig2_b.pdf", replace  //Right panel of Figure 2
gr export "fig2_b.eps", replace

*Panel A
collapse comptype, by(caseid)
label define comp 1 "Head of State" 2 "Head of Govt." 3 "The Govt./Cabinet" ///
	4 "First Chamber of Legis." 5 "Second Chamber of Legis." 6 "Both Chambers of Legis." ///
	7 "A court" 8 "Atty Gen/Pros Gen/Ombuds" 9 "Individual" 10 "Political Party" ///
	11 "Interest Group" 12 "Group of Citizens" 13 "Other" 14 "Firm" 

label values comptype comp
	
catplot comptype,  var1opts(sort(1) desc) scheme(s1mono) ytitle(Frequency) l1title("") title(Types of Complainants)
gr save "fig2_a", replace
gr export "fig2_a.pdf", replace //Left panel of Figure 2		
gr export "fig2_a.eps", replace
